feat: add periodic auto-refresh for per-user custom apps repos - #877
Conversation
System apps get a scheduled 12h background refresh (SYSTEM_APPS_AUTO_REFRESH), but per-user custom apps repos were only pulled when first saved or via the manual "Refresh" button on Settings -> Content. Add the same ticker pattern, gated behind a new CUSTOM_APPS_AUTO_REFRESH env var (default false), that iterates over every user with a configured repo and re-pulls it. Fixes tronbyt#876
📝 WalkthroughWalkthroughThe change adds the ChangesCustom Apps Refresh
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant NewServer
participant autoRefreshCustomAppsRepos
participant refreshAllCustomAppsRepos
participant Users
NewServer->>autoRefreshCustomAppsRepos: start background refresh
autoRefreshCustomAppsRepos->>autoRefreshCustomAppsRepos: wait for 12-hour ticker
autoRefreshCustomAppsRepos->>refreshAllCustomAppsRepos: refresh configured repositories
refreshAllCustomAppsRepos->>Users: query users with repository URLs
refreshAllCustomAppsRepos->>refreshAllCustomAppsRepos: refresh each repository independently
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
internal/server/handlers_user.go (1)
282-299: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd focused coverage for scheduler outcomes.
If
internal/server/handlers_user_test.godoes not already cover these functions, add tests for the disabled gate, the database-list failure, and continuation after oneEnsureRepofailure. TestrefreshAllCustomAppsReposdirectly so tests do not wait 12 hours.Also applies to: 304-317
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/server/handlers_user.go` around lines 282 - 299, Add focused tests in handlers_user_test.go for the scheduler and refresh flow: verify autoRefreshCustomAppsRepos exits when CustomAppsAutoRefresh is disabled, refreshAllCustomAppsRepos handles database-list failure, and continues processing after one EnsureRepo failure. Invoke refreshAllCustomAppsRepos directly rather than waiting on the 12-hour ticker, and reuse existing test fixtures or mocks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/server/handlers_user.go`:
- Around line 311-315: Introduce a shared per-repository-path lock and use it
around the EnsureRepo call in the scheduled refresh loop and the os.RemoveAll
path in handleSetUserRepo. Ensure both flows derive the same appsPath key and
serialize mutations for that path while allowing unrelated repositories to
proceed concurrently.
- Around line 311-315: Bound each scheduled repository refresh in the loop
around EnsureRepo with a finite timeout or cancellation mechanism, ensuring both
clone and fetch work for a user cannot stall subsequent users; update the
relevant EnsureRepo invocation and preserve the existing error logging and
per-user iteration.
---
Nitpick comments:
In `@internal/server/handlers_user.go`:
- Around line 282-299: Add focused tests in handlers_user_test.go for the
scheduler and refresh flow: verify autoRefreshCustomAppsRepos exits when
CustomAppsAutoRefresh is disabled, refreshAllCustomAppsRepos handles
database-list failure, and continues processing after one EnsureRepo failure.
Invoke refreshAllCustomAppsRepos directly rather than waiting on the 12-hour
ticker, and reuse existing test fixtures or mocks.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 21b067ee-d91e-478e-b060-084196f2b600
📒 Files selected for processing (4)
README.mdinternal/config/config.gointernal/server/handlers_user.gointernal/server/server.go
System apps get a scheduled 12h background refresh (
SYSTEM_APPS_AUTO_REFRESH), but per-user custom apps repos were only pulled when first saved or via the manual "Refresh" button on Settings -> Content. Add the same ticker pattern, gated behind a newCUSTOM_APPS_AUTO_REFRESHenv var (default false), that iterates over every user with a configured repo and re-pulls it.Fixes #876.
Summary by CodeRabbit
New Features
Documentation